<?php
/**
 * Created by PhpStorm.
 * User: 吕金鹏
 * Date: 2021/6/8
 * Time: 9:19 上午
 */

namespace app\index\controller;

use think\facade\Request;
use think\Controller;
use think\Db;
use think\facade\Cookie;
class Register extends Controller
{
    public function Register(){
        if(Request::isPost()){
            $data = input('post.');
            if($data['pass']!=$data['repass']){
                ajaxMsg(0,'两次密码不一致!');
            }
            $data['password'] = sha1($data['pass']);
            $phone = input('phone');
            if(Db::name("admin")->where('name',$data['name'])->where('idcard',$data['idcard'])->find()){
                ajaxMsg(0,'账号已经注册');
            }

            if(!isset($data['area'])||!isset($data['school'])){
                ajaxMsg(0,'学校信息有误！！');
            }

            $code1 = sha1("renzheng");$code2 = sha1("keti");

            $data['type'] =2;
            $data['rid'] = 7;//认证教师权限
            // $data['bumen'] = ;
            $data['lv'] = 4;
            $data['time'] = time();
            $data['status'] = 1;
            $data['first'] = 1;
            unset($data['kcode']);
            unset($data['repass']);
            unset($data['pass']);

            $res = Db::name("admin")->insert($data);
            if(!$res){
                ajaxMsg(0,'注册失败,网络错误');
            }
            $res = Db::name("admin")->where("name",$data['name'])->find();
            Cookie('admin',json_encode($res));
            ajaxMsg(1,'注册成功');
        }
        $area = Db::name("cate")->where("status",1)->where('pid',1)->select();
        $this->assign('area',$area);
        $code = input("code");
        $code1 = sha1("renzheng");$code2 = sha1("keti");
        $this->assign('code',$code);
        
        return $this->fetch("Register_kt");
        
        
    }
    public function sendmessage(){
        $phone = input('phone');

        $time = Cookie::get('time');

        if($time>time()-60){
            ajaxMsg(0,'验证码已发送');
        }
        $num = rand('1000','9999');
        $send_data['code'] = $num;

        Cookie::set('code',$num);
        Cookie::set('time',time());
        $res = sendMsg($phone,$send_data);
        ajaxMsg(1,'验证码已发送');
    }
    public function getqu(){
        $id = input('id');
        $qu = Db::name('cate')->where('pid',$id)->where('status',1)->select();
        ajaxMsg('1',$qu);
    }
    public function getschool(){
        $id = input('id');
        $qu = Db::name('cate')->where('pid',$id)->where('status',1)->select();
        ajaxMsg('1',$qu);
    }
}